package com.have.blog.base.validator.constraint;

import com.have.blog.base.constant.BlogConstant;
import com.have.blog.base.validator.annotation.IdValid;
import org.springframework.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IdValidator implements ConstraintValidator<IdValid, String> {
    @Override
    public void initialize(IdValid constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if (StringUtils.isEmpty(value.trim()) || value.length() != BlogConstant.THIRTY_TWO) {
            return false;
        }
        return true;
    }
}
